/*
 * @Description:时间选择
 * @Author: maskMan
 * @LastEditTime: 2024-10-17 19:05:49
 */
import { MARK } from '../define/variable'
import Config from './config'
import { playEffect, tips } from './shorts'
const { ccclass, property } = cc._decorator
@ccclass
export class msgTime extends cc.Component {
  @property(cc.Label)
  time_label: cc.Label = null
  select: number
  timeList: number[] = []
  currPointer: number = 0
  onLoad() {
    this._initData()
  }
  private _initData() {
    this.timeList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    for (let index = 0; index < 50; index++) {
      this.timeList.push(10 + (index + 1) * 5)
    }
    const index = this.timeList.findIndex((v) => v == this.select)
    if (index >= 0) {
      this.currPointer = index
    }
    this.time_label.string = this.select + '分钟'
    this.__resetColor()
  }
  /**重设时间颜色 */
  private __resetColor() {}
  /**确定点击 */
  onQueClick(e) {
    if (!this.select) {
      return tips('未选择时间')
    }
    playEffect('btn')
    this.node.destroy()
    this.node.emit(MARK.NODE_EVENT, this.select)
  }
  /**增加 */
  onAdd() {
    this.currPointer++
    if (this.currPointer >= this.timeList.length) {
      this.currPointer = this.timeList.length - 1
      return tips('最大时间')
    }
    this.select = this.timeList[this.currPointer]
    this.time_label.string = `${this.select}分钟`
    this.__resetColor()
  }
  /**减少 */
  onSub() {
    this.currPointer--
    if (this.currPointer < 0) {
      this.currPointer = 0
      return tips('最小时间')
    }
    this.select = this.timeList[this.currPointer]
    this.time_label.string = `${this.select}分钟`
    this.__resetColor()
  }
  /**选择类型 */
  onSelect(e, type) {}
  /**取消点击 */
  onCancelClick(e) {
    playEffect('btn')
    this.node.destroy()
    this.node.emit(MARK.NODE_EVENT, null)
  }
  /**窗口销毁 */
  onDestroy() {}
}
